package com.project.server.traffic;

import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.core.page.TableDataInfo;
import com.project.common.enums.BusinessType;
import com.project.common.utils.poi.ExcelUtil;
import com.project.server.domain.traffic.TTrafficViolation;
import com.project.server.service.traffic.ITTrafficViolationService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 交通违规信息Controller
 *
 * @author project
 * @date 2021-07-02
 */
@RestController
@RequestMapping("/server/violation")
public class TTrafficViolationController extends BaseController {

    @Resource
    private ITTrafficViolationService tTrafficViolationService;

    /**
     * 查询交通违规信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:violation:list')")
    @GetMapping("/list")
    public TableDataInfo list(TTrafficViolation tTrafficViolation) {
        startPage();
        List<TTrafficViolation> list = tTrafficViolationService.selectTTrafficViolationList(tTrafficViolation);
        return getDataTable(list);
    }


    /**
     * 导出交通违规信息列表
     */
    @PreAuthorize("@ss.hasPermi('server:violation:export')")
    @Log(title = "交通违规信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TTrafficViolation tTrafficViolation) {
        List<TTrafficViolation> list = tTrafficViolationService.selectTTrafficViolationList(tTrafficViolation);
        ExcelUtil<TTrafficViolation> util = new ExcelUtil<TTrafficViolation>(TTrafficViolation.class);
        return util.exportExcel(list, "交通违规信息列表");
    }

    /**
     * 获取交通违规信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:violation:query')")
    @GetMapping(value = "/{violationId}")
    public AjaxResult getInfo(@PathVariable("violationId") Long violationId) {
        return AjaxResult.success(tTrafficViolationService.selectTTrafficViolationById(violationId));
    }

    /**
     * 新增交通违规信息
     */
    @PreAuthorize("@ss.hasPermi('server:violation:add')")
    @Log(title = "交通违规信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TTrafficViolation tTrafficViolation) {
        return toAjax(tTrafficViolationService.insertTTrafficViolation(tTrafficViolation));
    }

    /**
     * 修改交通违规信息
     */
    @PreAuthorize("@ss.hasPermi('server:violation:edit')")
    @Log(title = "交通违规信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TTrafficViolation tTrafficViolation) {
        return toAjax(tTrafficViolationService.updateTTrafficViolation(tTrafficViolation));
    }

    /**
     * 删除交通违规信息
     */
    @PreAuthorize("@ss.hasPermi('server:violation:remove')")
    @Log(title = "交通违规信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{violationIds}")
    public AjaxResult remove(@PathVariable Long[] violationIds) {
        return toAjax(tTrafficViolationService.deleteTTrafficViolationByIds(violationIds));
    }
}
